package cn.ym.ymcc.service.impl;

import cn.ym.ymcc.domain.Systemdictionaryitem;
import cn.ym.ymcc.domain.Systemdictionaryitem;
import cn.ym.ymcc.dto.UpdateStateDto;
import cn.ym.ymcc.mapper.SystemdictionaryitemMapper;
import cn.ym.ymcc.mapper.SystemdictionaryitemMapper;
import cn.ym.ymcc.query.SystemdictionaryitemQuery;
import cn.ym.ymcc.result.JSONResult;
import cn.ym.ymcc.result.PageList;
import cn.ym.ymcc.service.ISystemdictionaryitemService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 210513347@qq.com
 * @since 2023-05-04
 */
@Service
public class SystemdictionaryitemServiceImpl extends ServiceImpl<SystemdictionaryitemMapper, Systemdictionaryitem> implements ISystemdictionaryitemService {

    @Autowired
    private SystemdictionaryitemMapper systemdictionaryitemMapper;

    @Override
    public PageList<Systemdictionaryitem> queryPage(SystemdictionaryitemQuery query) {
        //1.查询总数量 - 前端计算分页栏
        Long count = systemdictionaryitemMapper.queryCount(query);
        if(count < 1){//没有数据
            return new PageList<>();
        }
        //2.查询当前页的分页数据 - 前端展示当前页的数据
        List<Systemdictionaryitem> list = systemdictionaryitemMapper.queryData(query);
        return new PageList<>(count,list);
    }
    
    

    @Override
    public void updateByParentId(UpdateStateDto dto) {
        Systemdictionaryitem systemdictionaryitem = systemdictionaryitemMapper.selectById(dto.getId());
        systemdictionaryitem.setParentId(dto.getParentId());
        systemdictionaryitemMapper.updateById(systemdictionaryitem);
    }

    @Override
    public List<Systemdictionaryitem> listByParentId(Long parentId) {

        return  systemdictionaryitemMapper.listByParentId(parentId);
    }
}
